from database.db_handler import MysqlHander
from common.my_http import MyHttp
import urllib.request
from bs4 import BeautifulSoup
from common.macro_data import MacroData
import glob
import jieba
import re
import threading
import hashlib

'''
宏观数据
'''

class CaizhengbuData:
    def __init__(self):
        self.macro = MacroData()
        pass
    
    def caizhengbu(self):
        url = "http://www.mof.gov.cn/zhengwuxinxi/"
        bs4_data = MyHttp.bs4_utf8_data(url)
        for ul in bs4_data.find_all(name="ul", attrs={'class':'xwfb_listflul'}):
            for valid_data in ul.find_all(name="li"):
                #print(str(valid_data))
                url_data = valid_data.find("a").attrs["href"]
                title_data = valid_data.find("a").text.replace(u"（","(").replace(u"）",")")
                date_data = valid_data.find("span").text.replace(".","-")
                print(url_data + title_data + date_data)
                self.macro.add_macro_data(date_data, 100, title_data, url_data, "中国财政部")


    
    def get_data(self):
        self.caizhengbu()

def caizhengbu_api():
    d = CaizhengbuData()
    d.get_data()

if __name__ == '__main__':
    caizhengbu_api()
